package com.orhon.smartcampus.modules.base.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.orhon.smartcampus.modules.teacher.entity.TInformation;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "base_subjects", schema = "smartcloud", catalog = "")
@Slf4j
@JsonIgnoreProperties({"id", "subjectName","hibernateLazyInitializer","handler"})
public class Subjects {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	@JsonIgnore
	private Long id;

	@Column(name = "subject_name", nullable = true)
	private String subjectName;

	@Column(name = "subject_slug", nullable = true, length = 191)
	private String subjectSlug;

	@Column(name = "subject_number", nullable = true, length = 191)
	private String subjectNumber;

	@Column(name = "subject_order", nullable = true)
	private Integer subjectOrder;

	@Column(name = "mark", nullable = true, length = 255)
	private String mark;

	@Column(name = "icon", nullable = true, length = 191)
	private String icon;

	@Column(name = "type", nullable = false)
	private String type;

	@Column(name = "created_at", nullable = true)
	private Date createdAt;

	@Column(name = "updated_at", nullable = true)
	private Date updatedAt;

	@Column(name = "deleted_at", nullable = true)
	private Date deletedAt;



	//学段
	//@JsonIgnoreProperties("subjects")
	@ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
	@JoinTable(
			name = "base_subject_period_relation",
			joinColumns = { @JoinColumn(name = "subject_id")},
			inverseJoinColumns = { @JoinColumn(name = "period_id")}
	)
	@NotFound(action= NotFoundAction.IGNORE)
	@Where(clause = "ISNULL(deleted_at)")
	List<Periods> period;



	//年级
	@ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
	@JoinTable(
			name = "base_subjects_grade_relation",
			joinColumns = { @JoinColumn(name = "subject_id")},
			inverseJoinColumns = { @JoinColumn(name = "grade_id")}
	)
	@Where(clause = "ISNULL(deleted_at)")
	@NotFound(action=NotFoundAction.IGNORE)
	List<Grades> grade;


	//教职工
	@ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
	@JoinTable(
			name = "base_teacher_subjects_relation",
			joinColumns = { @JoinColumn(name = "subjects_id")},
			inverseJoinColumns = { @JoinColumn(name = "teacher_id")}
	)
	@NotFound(action= NotFoundAction.IGNORE)
	@Where(clause = "ISNULL(deleted_at)")
	List<TInformation> teacher;




}
